package com.example.android_20190529_01;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class LinearLayoutActivity extends AppCompatActivity {
    Button btn_horizontal;
    Button btn_vertical;
    Button btn_left;
    Button btn_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.uc1);
        btn_horizontal=findViewById(R.id.btn_horizontal);
        btn_vertical=findViewById(R.id.btn_vertical);
        btn_left=findViewById(R.id.btn_left);
        btn_back=findViewById(R.id.btn_back);
        btn_back.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                startActivity(new Intent(LinearLayoutActivity.this,MainActivity.class));
            }
        });
//        水平居中
        btn_horizontal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LinearLayout h1=findViewById(R.id.uc01);
                h1.setOrientation(LinearLayout.HORIZONTAL);
                h1.setGravity(Gravity.CENTER_HORIZONTAL);
            }
        });
//        垂直居中
        btn_vertical.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LinearLayout h1=findViewById(R.id.uc01);
                h1.setOrientation(LinearLayout.VERTICAL);
                h1.setGravity(Gravity.CENTER_VERTICAL);
                h1.setGravity(Gravity.CENTER_HORIZONTAL);
            }
        });
//
        btn_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LinearLayout h3=findViewById(R.id.uc01);
                h3.setGravity(Gravity.LEFT);
            }
        });

    }
}
